//
//  VillageDetailsCell.m
//  Village
//
//  Created by 程虎 on 2017/9/14.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "VillageDetailsCell.h"

@implementation VillageDetailsCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *cellID = @"VillageDetailsCell";
    VillageDetailsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    return cell;
}

- (void)setModel:(CodeInfo *)model
{
    _model = model;
    UIImage *pic = [UIImage imageNamed:_model.icon];
    CGFloat scale = pic.size.height / pic.size.width;
    self.titleLab.numberOfLines = 0;
    self.titleLab.text = [Globle getInstance].account.areaname;
     CGFloat hight = [self getHeightByWidth1:330*kScreenScaleX title:[Globle getInstance].account.areaname font:self.titleLab.font];
    CGFloat top = 30;
    CGFloat left = 14 * AutoScaleX;
    self.titleLab.sd_layout
    .topSpaceToView(self.contentView, top)
    .leftSpaceToView(self.contentView, left)
    .rightSpaceToView(self.contentView, left)
    .heightIs(hight);
    
    self.documentsImg.image = pic;
    self.documentsImg.sd_layout.autoHeightRatio(scale);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    CGFloat top = 30;
    CGFloat left = 14 * AutoScaleX;
    
    self.titleLab.sd_layout
    .topSpaceToView(self.contentView, top)
    .leftSpaceToView(self.contentView, left)
    .rightSpaceToView(self.contentView, left)
    .heightIs(18);
    
    self.desLab.sd_layout
    .leftEqualToView(self.titleLab)
    .topSpaceToView(self.titleLab, 14)
    .rightEqualToView(self.titleLab)
    .heightIs(14);
    
    self.documentsImg.sd_layout
    .leftEqualToView(self.desLab)
    .topSpaceToView(self.desLab, top)
    .rightEqualToView(self.desLab);
    
    self.noticeLab.sd_layout
    .leftSpaceToView(self.contentView, 26)
    .topSpaceToView(self.documentsImg, top)
    .rightSpaceToView(self.contentView, 26)
    .autoHeightRatio(0);
    
    [self setupAutoHeightWithBottomView:self.noticeLab bottomMargin:20];
}
- (CGFloat)getHeightByWidth1:(CGFloat)width title:(NSString *)title font:(UIFont *)font
{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
    label.text = title;
    label.font = font;
    label.numberOfLines = 0;
    [label sizeToFit];
    CGFloat height = label.frame.size.height;
    return height;
}
@end
